
package com.mall.common.controller.directive;

import java.io.IOException;
import java.util.Map;

import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Repository;

import com.mall.common.util.UploadUtil;

import freemarker.core.Environment;
import freemarker.template.TemplateDirectiveBody;
import freemarker.template.TemplateDirectiveModel;
import freemarker.template.TemplateException;
import freemarker.template.TemplateModel;

@Repository
public class PicDirectiveModel implements TemplateDirectiveModel {
	
	@SuppressWarnings({ "unchecked", "rawtypes" })
	public void execute(Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body) 
		throws TemplateException, IOException {
		String pic = DirectiveUtils.getString("pic", params);
		String postfix = DirectiveUtils.getString("postfix", params);
		
		if(StringUtils.isEmpty(pic)) {
			pic = "filePlugin:///img/default.jpg";
		}
		pic = UploadUtil.replacePath(pic);
		//env.getOut().write(UploadUtil.getImagePath(pic, postfix));
		env.getOut().write(pic);
	}
}